/** @file QTC_GroupLoader.qml
@brief The Qt-Complex loader for the grouped elements (buttons, switches, toolbars, ...)

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

import QtQuick 1.0
import "Tools.js" as QTCtools

Item {
    id: itemLoader

    // Loader properties to be assigned in the program
    property string obj: ""     // Object to load

    property string obj_color:  ""      // Generic color
    property string obj_icon: ""        // Generic icon assigned to buttons
    property bool obj_flag: false       // Generic flag to enable/disable object options
    property string obj_button: ""      // Button file name.

    // Set this property if the loader should destroy the object on mouse click event
    property bool destroy: false
    // Set this property to false to disable buttonclick over the object.
    property bool enabled: true

    // The signals connected with the object types
    signal clicked;

    Loader {
        id: objGroupLoad

        // Inline functions returning the requested property
        function getIcon() { return itemLoader.obj_icon; }
        function getFlag() { return itemLoader.obj_flag; }
        function getColor() { return itemLoader.obj_color; }
        function getButton() { return itemLoader.obj_button; }
        function objDestroy() { if(destroy == true) { source = ""; } }

        function getWidth() { return itemLoader.width; }
        function getHeight() { return itemLoader.height; }
        function getEnabled() { return itemLoader.enabled; }

        function setSourceName() {
            if (itemLoader.obj != "")
                return itemLoader.obj + ".qml"
            else
                return "";
        }

        // The object source definition
        source: setSourceName();

        // The connections to the possible signals returned by the objects
        Connections {
            target: objGroupLoad.item
            ignoreUnknownSignals: true
            // Signal returned by the objects
            onObjClicked: {
                itemLoader.clicked();
            }
        }
    }
}
